#include <pthread.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
#include <linux/input.h>
#include <stdio.h>




int main(){
	int ret=0;
	struct input_event t;
	fd_set fds;
	struct timeval timeout={1,0}; 
	int fd=-1;
        fd=open("/dev/input/event2",O_RDONLY);
        if(fd<0){
                //msgbox.....
                return -1;
        }


	//memset(buf,0,6);
	while(1){
		FD_ZERO(&fds);
		FD_SET(fd,&fds);
		ret=select(fd+1,&fds,NULL,NULL,&timeout);
		if(ret){
			read(fd, &t, sizeof(t));
			if(t.type==EV_KEY)
			//if(t.value==0||t.value==1)
			//printf ("key %d %s\n", t.code,(t.value) ? "DOWN" : "UP");
			if(t.value)
			printf ("key %d %s\n", t.code,"DOWN");
			//if(t.code==KEY_ESC)key=BTN_EXIT;
		}
	}

	return ret;

	//pthread_t pid_input;
        //pthread_create(&pid_input,0,input::receive,0);


	//pthread_join(pid_input,NULL);
















}
